<?php
/**
* Copyright 2009 Waag Society <http://www.waag.org>
* This file is part of Annotrax.
*
* Annotrax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Annotrax is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Annotrax.
* If not, see http://www.gnu.org/licenses/gpl.html
*/

?>
<?php
/**
 * Model for keyword
 *
 * @author Matthijs van Henten  <Matthijs@waag.org>
 * @license GNU GPL 2.0
 * @verson 0.1
 * @copyright Copyright (c) 2009, Waag Society
 */
class Default_Model_Keyword extends At_Model{
    // data
    protected $_id;
    protected $_name;
    protected $_domainId;

    // properties
	protected $channel;
	protected $annotation;

	/**
	 * toString returns the name of this keyword
	 */
    public function __toString(){
        return (string) $this->_name;
    }

	/**
	 * return domain_id that is never NULL
	 */
	public function getDomainId(){
		/*
		if( null == $this->_domainId ){
			$this->_domainId = 1;
		}
		*/
		return $this->_domainId;
	}

	/**
	*  @param int $id Integer value
	 * @return $this Fluent interface
	 */
    public function setId( $id ){
        $this->_id = (int) $id;
		return $this;
    }

	public function setAnnotation( Default_Model_Annotation $annotation ){
		$this->annotation = $annotation;
		return $this;
	}

	public function getAnnotation(){
		// note that setting this getter prevends database lookups in this case
		return $this->annotation;
	}

	/**
	 * Setter for channel
	 *
	 * @param Default_Model_Channel $channel Sets the channel object to be associated
	 * @return $this Fluent interface
	 */
	public function setChannel( Default_Model_Channel $channel ){
		$this->channel = $channel;
		return $this;
	}

	/**
	 * @return Default_Model_Channel Channel or null
	 */
	public function getChannel(){
		// note that setting a setter prevends database lookups in this case
		return $this->channel;
	}

    /**
     * @return object $this fluent interface
     */
    protected function find(){
		// to prevent recursion
		// these functions have been split
		if( null == $this->id && null !== $this->name && null !== $this->domainId ){
			$this->getMapper()->findByName( $this );
		}
		else if( null !== $this->id ){
			$this->getMapper()->find( $this );
		}
    }
}
